package com.dingding.util;

import com.dingding.config.URLConstant;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiProcessListbyuseridRequest;
import com.dingtalk.api.response.OapiProcessListbyuseridResponse;
import com.taobao.api.ApiException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 流程
 * @author: zyj
 * @create: 2020-03-11 16:39
 **/
@Service
public class ProcessUtil {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    AccessTokenUtil accessTokenUtil;

    /**
    * @Description: 流程列表
    * @Param: [pageNumber, pageSize]
    * @return: java.util.List
    * @Author: zyj
    * @Date: 2020/3/11
    */
    public List<OapiProcessListbyuseridResponse.ProcessTopVo> listProcess(long pageNumber, long pageSize){
        try {
            DingTalkClient client = new DefaultDingTalkClient(URLConstant.PROCESS_LIST);
            OapiProcessListbyuseridRequest req = new OapiProcessListbyuseridRequest();
            req.setOffset(PageUtil.offset(pageNumber, pageSize));
            req.setSize(pageSize);
            OapiProcessListbyuseridResponse rsp = client.execute(req, accessTokenUtil.getToken(URLConstant.COMPANY));
            logger.info("流程列表msg={}", rsp.getBody());
            long errorCode = rsp.getErrcode();
            if(0==errorCode){
                List<OapiProcessListbyuseridResponse.ProcessTopVo> value = rsp.getResult().getProcessList();
                return value;
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }

        return null;
    }


}
